package com.ruoyi.web.controller.dr;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dr.domain.DrProductData;
import com.ruoyi.dr.service.IDrProductDataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品基本信息Controller
 * 
 * @author ruoyi
 * @date 2025-07-12
 */
@RestController
@RequestMapping("/dr/productData")
public class DrProductDataController extends BaseController
{
    @Autowired
    private IDrProductDataService drProductDataService;

    /**
     * 查询商品基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('dr:data:list')")
    @GetMapping("/list")
    public TableDataInfo list(DrProductData drProductData)
    {
        startPage();
        List<DrProductData> list = drProductDataService.selectDrProductDataList(drProductData);
        return getDataTable(list);
    }

    /**
     * 导出商品基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('dr:data:export')")
    @Log(title = "商品基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DrProductData drProductData)
    {
        List<DrProductData> list = drProductDataService.selectDrProductDataList(drProductData);
        ExcelUtil<DrProductData> util = new ExcelUtil<DrProductData>(DrProductData.class);
        util.exportExcel(response, list, "商品基本信息数据");
    }

    /**
     * 获取商品基本信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('dr:data:query')")
    @GetMapping(value = "/{productId}")
    public AjaxResult getInfo(@PathVariable("productId") String productId)
    {
        return success(drProductDataService.selectDrProductDataByProductId(productId));
    }

    /**
     * 新增商品基本信息
     */
    @PreAuthorize("@ss.hasPermi('dr:data:add')")
    @Log(title = "商品基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DrProductData drProductData)
    {
        return toAjax(drProductDataService.insertDrProductData(drProductData));
    }

    /**
     * 修改商品基本信息
     */
    @PreAuthorize("@ss.hasPermi('dr:data:edit')")
    @Log(title = "商品基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DrProductData drProductData)
    {
        return toAjax(drProductDataService.updateDrProductData(drProductData));
    }

    /**
     * 删除商品基本信息
     */
    @PreAuthorize("@ss.hasPermi('dr:data:remove')")
    @Log(title = "商品基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{productIds}")
    public AjaxResult remove(@PathVariable String[] productIds)
    {
        return toAjax(drProductDataService.deleteDrProductDataByProductIds(productIds));
    }
}
